package org.zero.service.impl;

import javax.annotation.Resource;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.zero.mapper.UserMapper;
import org.zero.model.User;
import org.zero.service.UserService;

/**
 * @author Zero (cnzeropro@qq.com)
 * @date 2021/10/26 11:47
 */
@Service("userService")
@CacheConfig(cacheManager = "cacheManager", cacheNames = "redisCache")
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    @CacheEvict(key = "#root.targetClass.getName()+':'+#id")
    public int deleteByPrimaryKey(Integer id) {
        return userMapper.deleteByPrimaryKey(id);
    }

    @Override
    @CachePut(key = "#root.targetClass.getName()+':'+#record.id")
    public int insert(User record) {
        return userMapper.insert(record);
    }

    @Override
    @CachePut(key = "#root.targetClass.getName()+':'+#record.id")
    public int insertSelective(User record) {
        return userMapper.insertSelective(record);
    }

    @Override
    @Cacheable(key = "#root.targetClass.getName()+':'+#id")
    public User selectByPrimaryKey(Integer id) {
        return userMapper.selectByPrimaryKey(id);
    }

    @Override
    @CacheEvict(key = "#root.targetClass.getName()+':'+#record.id")
    public int updateByPrimaryKeySelective(User record) {
        return userMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    @CacheEvict(key = "#root.targetClass.getName()+':'+#record.id")
    public int updateByPrimaryKey(User record) {
        return userMapper.updateByPrimaryKey(record);
    }
}

